package cn.myjerry.test.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 测试ResultSet的用法
 * @author Jerry
 *
 */
public class Demo04 {
	// JDBC 驱动名及数据库 URL
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    static final String DB_URL = "jdbc:mysql://localhost:3306/testjdbc?useSSL=true&useUnicode=true&characterEncoding=utf8";
    
    // 数据库的用户名与密码，需要根据自己的设置
    static final String USER = "root";
    static final String PASS = "Jerry1912317";
	
	public static void main(String[] args) throws Exception {
		// 加载驱动类
		Class.forName(JDBC_DRIVER);
		// 建立连接
		Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
		conn.setAutoCommit(false);	// 设为手动操作

		long start = System.currentTimeMillis();
		
		Statement stmt = conn.createStatement();

		for(int i=0;i<20000;i++) {
			stmt.addBatch("INSERT INTO User (Name,PassWord,RegTime) VALUES ('Jerry"+i+"', 123456, now())");
		}
		
		stmt.executeBatch();
		
		conn.commit();
		
		long end = System.currentTimeMillis();
		System.out.println("插入20000条数据，耗时(ms)：" + (end-start));
		
		if(stmt != null) {
			stmt.close();
		}
		if(conn != null) {
			conn.close();
		}
	}
}
